<script setup lang='ts'>
import { onMounted, ref } from 'vue';
const inpRef = ref<HTMLInputElement | null>(null)
onMounted(() => {
  // 非空断言
  // inpRef.value!.focus()
  // 判断
  // if (inpRef.value) {
  //   inpRef.value.focus()
  // }
  // 可选链
  inpRef.value?.focus()
})

const aRef = ref<HTMLAnchorElement | null>(null)
onMounted(() => {
  aRef.value!.href = 'aaaaaa'
})
</script>

<template>
  <div>
    <input type="text" ref="inpRef">
    <a href="#" ref="aRef">点击</a>
  </div>
</template>

<style scoped></style>